﻿#region Using Statements
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
using Neat;
using Neat.Mathematics;
using Neat.GUI;
using Neat.Graphics;
using Sectors;
using Microsoft.Xna.Framework.Input;
using System;
using System.Diagnostics;
using System.Windows.Forms;
using System.IO;
using System.Collections.Generic;
#endregion

namespace SectorsDesigner
{
    public partial class SectorsMapMakerControl : GraphicsDeviceControl
    {
        public Dictionary<string, Texture2D> Textures;

        public void InitializeAssets()
        {
            Textures = new Dictionary<string, Texture2D>();
        }

        public void LoadTexture(string assetname, string path)
        {
            assetname = assetname.ToLower();
            if (Textures.ContainsKey(assetname))
                Textures[assetname] = Content.Load<Texture2D>(path);
            else
                Textures.Add(assetname, Content.Load<Texture2D>(path));
        }

        public void LoadTextureList(string path)
        {
            if (!File.Exists(path))
            {
                MessageBox.Show("File " + path + " not found.", "Error loading texture list");
                return;
            }
            foreach (var item in File.ReadAllLines(path))
            {
                //try
                {
                    int i = item.IndexOf(' ');
                    LoadTexture(item.Substring(0, i).Trim(), item.Substring(i+1, item.Length - i - 1));
                }
                //catch
                {
                  //  MessageBox.Show("Error loading\n" + item);
                }
            }
        }

        public bool HasTexture(string assetname)
        {
            return Textures.ContainsKey(assetname.ToLower());
        }

        public Texture2D GetTexture(string assetname)
        {
            return Textures[assetname.ToLower()];
        }
    }
}